package com.bluesky.plum.domain.repository.search.condition;

import com.bluesky.plum.domain.repository.search.operator.BooleanOperator;
import com.bluesky.plum.domain.repository.search.operator.IntegerOperator;
import com.bluesky.plum.domain.repository.search.operator.StringOperator;

/**
 * it is Search Condition, should be a tree.
 * 
 * @author jack
 * 
 */
public class Condition {

	public Object getValue() {
		// if (type == Type.Value)
		// return simpleValue;
		// else
		// return operator.operate(o1.getValue(), o2.getValue());
		return null;
	}

	@Override
	public String toString() {
		// if (type == Type.Value)
		// return simpleValue.toString();
		// else if (type == Type.PlaceHolder)
		// return placeHolderName;
		// else
		// return String.format("(%s %s %s)", o1, operator, o2);
		return null;
	}

	public static void main(String[] args) {
		Condition a = new SimpleValueCondition("AABBC");
		Condition b = new SimpleValueCondition("%A%");
		Condition c = new ExpressCondition(a, b, StringOperator.Like);

		Condition a11 = new SimpleValueCondition(Integer.valueOf(10));
		Condition b11 = new SimpleValueCondition(Integer.valueOf(10));
		Condition c11 = new ExpressCondition(a11, b11,
				IntegerOperator.LessThanOrEquals);

		Condition a12 = new SimpleValueCondition(Integer.valueOf(10));
		Condition b12 = new SimpleValueCondition(Integer.valueOf(10));
		Condition c12 = new ExpressCondition(a12, b12,
				IntegerOperator.LessThanOrEquals);

		Condition c1 = new ExpressCondition(c11, c12, BooleanOperator.Or);

		Condition t = new ExpressCondition(c, c1, BooleanOperator.And);

		System.out.println(t + "=" + t.getValue());

		Condition placeHolder = new PlaceHolderCondition("P.name");
		Condition nameCondition = new SimpleValueCondition("rose");
		Condition t2 = new ExpressCondition(placeHolder, nameCondition,
				StringOperator.Equals);
		System.out.println(t2);

	}
}
